﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.DataVisualization.Charting;
using dllLink;

namespace ASPGerant
{
    public partial class ProduitStruct : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            //Nécessaire pour pouvoir utiliser SQL Server CE avec un site ASP
            AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);

            // Create new data series and set it's visual attributes
            Series series = new Series("JPM Star garanti");
            series.ChartType = SeriesChartType.Line;
            series.BorderWidth = 3;
            series.ShadowOffset = 2;
            Interface adaptater = new Interface();
            adaptater.connectBD();
            AdpDts result = adaptater.selectBD("Cotation, Date", Interface.ProduitStruc, "1=1 ORDER BY date asc");

            DataTable dt = result.dts.Tables[0];
            foreach (DataRow r in dt.Select())
            {
                String date = r["Date"].ToString();
                String[] test = date.Substring(0, 10).Split('/');
                DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                series.Points.AddXY(dateTimer, r["Cotation"]);
            }
            adaptater.disconnectBD();
            // Add series into the chart's series collection
            Chart1.Series.Add(series);
            Chart1.Series["JPM Star garanti"]["ShowMarkerLines"] = "True";

            Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;
        }


        public String dateMin()
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            String temp = adapter.dateMinCoteBD(Interface.ProduitStruc);
            adapter.disconnectBD();
            return temp;
        }

        public String dateMax()
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            String temp = adapter.dateMaxCoteBD(Interface.ProduitStruc);
            adapter.disconnectBD();
            return temp;
        }
        public Double lastCote()
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            Double temp = adapter.lastCoteBD(Interface.ProduitStruc);
            adapter.disconnectBD();
            return temp;
        }
    }
}
